package com.tanhua.server.controller;

import com.tanhua.domain.vo.SingleCommentVo;
import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/movements")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 单条动态
     */
    @GetMapping("/{id}")
    public ResponseEntity findSingleComment(@PathVariable("id") String id) {
        //1.调用service层 传入发布id 返回SingleCommentVo
        SingleCommentVo singleComment= commentService.findSingleComment(id);
        //2.返回状态信息
        return ResponseEntity.ok(singleComment);
    }

    /**
     * 动态-点赞
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id")String id) {
        //调用CommentService方法 返回点赞数量
        Integer count=commentService.likeCount(id);
        //返回状态信息
        return  ResponseEntity.ok(count);
    }

    /**
     * 动态-取消点赞
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity unlike(@PathVariable("id")String id) {
        //调用CommentService方法 返回点赞数量
        Integer count=commentService.removeLikeStatus(id);
        //返回状态信息
        return  ResponseEntity.ok(count);
    }
    /**
     * 动态-喜欢
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id")String id) {
        //调用CommentService方法 返回点赞数量
        Integer count=commentService.loveCount(id);
        //返回状态信息
        return  ResponseEntity.ok(count);
    }

    /**
     * 动态-取消喜欢
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id")String id) {
        //调用CommentService方法 返回点赞数量
        Integer count=commentService.removeLoveStatus(id);
        //返回状态信息
        return  ResponseEntity.ok(count);
    }

}
